package com.redisdemo.utlis;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * <h3>redisDemo</h3>
 * <p>json工具类</p>
 *
 * @author gdw
 * @since 2024-06-27 17:00:24
 */
public class JsonUtils {
    /**
     * 只获取JSON对应的数据
     * @param jsonString
     * @param name
     * @return
     * @throws Exception
     */
    public static String extractShuValue(String jsonString,String name) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode rootNode = mapper.readTree(jsonString);
        String shuValue = rootNode.get(name).asText();
        return shuValue;
    }
}
